package agent.fromKanYun.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 日志类 ---> 待织入得Log类
 */
public class LogEmbed implements InvocationHandler {

    private IUserDao target;

    /**
     * 对target进行封装
     */
    public IUserDao getTarget() {
        return target;
    }

    public void setTarget(IUserDao target) {
        this.target = target;
    }

    private void beforeMethod(){
        System.out.println("add start...");
    }

    private void afterMethod(){
        System.out.println("add end...");
    }

    /**
     * 这里用到了反射
     * @param proxy 代理对象
     * @param method 目标方法
     * @param args 目标方法里面参数列表
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        beforeMethod();
        method.invoke(target,args);
        System.out.println("LogEmbed --invoke-> method = " + method.getName());
        afterMethod();
        return null;
    }
}
